package com.javaspeak.designpatterns.go4.creational.singleton;

/**
 * This class is a singleton. It has a private constructor so it cannot be
 * instantiated directly by other classes.  Instead it has a static block
 * which initializes the instance which can then be retrieved using a static
 * getInstance() method.
 * <p>
 * Once the instance has been retrieved the buildSquare() method can be called
 * on the instance.
 *
 * @author John Dickerson
 */
public class ShapeManager {

    private final static ShapeManager instance;

    static {
        // static block used for initialization
        instance = new ShapeManager();
    }


    /**
     * Private constructor
     */
    private ShapeManager(){}


    /**
     * This method provides the only access to an instance of ShapeManager
     *
     * @return instance of ShapeManager
     */
    public static ShapeManager getInstance(){

        return instance;
    }


    /**
     * Instance method
     *
     * @return
     */
    public Square buildSquare(){

        return new Square();
    }
}
